const mongoose = require("mongoose")
const ordersModel = mongoose.model("orders")

module.exports.add = async data => {
  const result = await ordersModel.create(data)
  return result
}
module.exports.add = async data => {
  const result = await ordersModel.create(data)
  return result
}
module.exports.getId = async id => {
  const result = await ordersModel.findOne({_id:id})
  return result
}
module.exports.changeOfferCar = async id => {
  const result = await ordersModel.updateOne({_id:id},{offerCar:true})
  return result
}
module.exports.changerentCheck = async id => {
  const result = await ordersModel.updateOne({_id:id},{rentCheck:true})
  return result
}
module.exports.changeoverOrder = async id => {
  const result = await ordersModel.updateOne({_id:id},{overOrder:true})
  return result
}
module.exports.list = async () => {
  const result = await ordersModel.find({}).populate({
    path:"leaseUser"
  }).populate({
    path:"rentUser"
  }).populate({
    path:"car"
  })
  return result
}